package ShunFeng;

import java.util.Arrays;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/20 15:34
 */
public class MAIN {

    public static void main(String[] args) {
        int[] a = {3, -2, -1, 5, 6};
        int[] result = new int[ a.length ];
        result[ a.length - 1 ] = a[ a.length - 1 ];
        int[] dp = new int[ a.length ];
        for (int i = a.length - 1; i > 0; --i) {
            dp[ i ] = getSub(result, i);
            result[ i - 1 ] = a[ i - 1 ] - dp[ i ];
        }
        System.out.println(Arrays.toString(result));

    }

    public static int getSub(int[] arr, int start) {
        int sum = 0;
        boolean status = false;
        for (int i = start; i < arr.length; i++) {
            if (!status) {
                sum += (-1 * arr[ i ]);
                status = true;
            } else {
                sum += arr[ i ];
                status = false;
            }
        }
        return sum;
    }

}
